/**
 * 题库分类管理初始化
 */
var QuestionCategory = {
    id: "QuestionCategoryTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
QuestionCategory.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '分类名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
        {title: '父分类', field: 'pname', visible: true, align: 'center', valign: 'middle'},
        {title: '比重', field: 'proportion', visible: true, align: 'center', valign: 'middle'},
        {title: '是否可用', field: 'available', visible: true, align: 'center', valign: 'middle'},
        {title: '备注', field: 'remarks', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
QuestionCategory.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        QuestionCategory.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加题库分类
 */
QuestionCategory.openAddQuestionCategory = function () {
    var index = layer.open({
        type: 2,
        title: '添加题库分类',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/questionCategory/questionCategory_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看题库分类详情
 */
QuestionCategory.openQuestionCategoryDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '题库分类详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/questionCategory/questionCategory_update/' + QuestionCategory.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除题库分类
 */
QuestionCategory.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/questionCategory/delete", function (data) {
            Feng.success("删除成功!");
            QuestionCategory.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("questionCategoryId", this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询题库分类列表
 */
QuestionCategory.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    QuestionCategory.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = QuestionCategory.initColumn();
    var table = new BSTable(QuestionCategory.id, "/questionCategory/list", defaultColunms);
    table.setPaginationType("client");
    QuestionCategory.table = table.init();
});
